package exercise.jslide.jslide.view.tools;


import exercise.jslide.jslide.app.AppContext;

import exercise.jslide.jslide.model.image.ImageElement;
import exercise.jslide.jslide.view.EditorView;
import javafx.scene.Cursor;


public class ImageTool implements Tool{
    private AppContext appContext;
    private EditorView editorView;
    private ImageElement currentImage;
    private double startX, startY;

    public ImageTool(EditorView editorView)
    {
        this.appContext = AppContext.getInstance();
        this.editorView = editorView;
    }








    @Override
    public void activate() {
        editorView.setCursor(Cursor.CROSSHAIR);
    }

    @Override
    public void deactivate() {
        editorView.setCursor(Cursor.DEFAULT);
        currentImage = null;
    }

    @Override
    public void handleMousePressed(double x, double y) {
//        try {
//            currentImage = shapeClass.getDeclaredConstructor().newInstance();
//            startX = x;
//            startY = y;
//            currentImage.setX(startX);
//            currentImage.setY(startY);
//
//            appContext.getCurrentPresentation()
//                    .getCurrentSlide()
//                    .addElement(currentImage);
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
    }

    @Override
    public void handleMouseDragged(double x, double y) {
//        currentImage.setCurrentX(x);
//        currentImage.setCurrentY(y);
//
//        if (currentImage != null) {
//            // 计算宽度和高度
//            currentImage.setWidth(Math.abs(x - startX));
//            currentImage.setHeight(Math.abs(y - startY));
//
//            // 处理负值情况
////            if (x < startX) {
////                currentShape.setX(x);
////            }
////            if (y < startY) {
////                currentShape.setY(y);
////            }
//
//            editorView.redraw();
//        }
    }



    @Override
    public void handleMouseReleased(double x, double y) {
//        if (currentImage != null) {
//            AddShapeCommand addShapeCommand = new AddShapeCommand(appContext.getCurrentPresentation(), currentImage);
//            appContext.getUndoManager().executeCommand(addShapeCommand);
//            currentImage = null;
//            // 可以自动切换回选择工具
//            editorView.setCurrentTool(new SelectTool(editorView));
//        }

        // 可以自动切换回选择工具
        editorView.setCurrentTool(null);
    }

}
